package Thread;

/**
 * 创建线程方法2
 */
class MyRunnable implements Runnable {

    @Override
    public void run() {
        //这里写的代码即将创建出的线程,要执行的任务逻辑
        while (true) {
            System.out.println("Hello Thread");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

public class demo2 {
    public static void main(String[] args) throws InterruptedException {
        MyRunnable myRunnable = new MyRunnable();
        Thread t = new Thread(myRunnable);
        t.start();
        while (true) {
            System.out.println("Hello Main");
            Thread.sleep(1000);
        }
    }
}